<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="author" content="James McCreight" />

<meta name="date" content="2017-05-01" />

<title>Get data from multiple netcdf files</title>



<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
  margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>



<link href="data:text/css;charset=utf-8,body%20%7B%0Abackground%2Dcolor%3A%20%23fff%3B%0Amargin%3A%201em%20auto%3B%0Amax%2Dwidth%3A%20700px%3B%0Aoverflow%3A%20visible%3B%0Apadding%2Dleft%3A%202em%3B%0Apadding%2Dright%3A%202em%3B%0Afont%2Dfamily%3A%20%22Open%20Sans%22%2C%20%22Helvetica%20Neue%22%2C%20Helvetica%2C%20Arial%2C%20sans%2Dserif%3B%0Afont%2Dsize%3A%2014px%3B%0Aline%2Dheight%3A%201%2E35%3B%0A%7D%0A%23header%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0A%23TOC%20%7B%0Aclear%3A%20both%3B%0Amargin%3A%200%200%2010px%2010px%3B%0Apadding%3A%204px%3B%0Awidth%3A%20400px%3B%0Aborder%3A%201px%20solid%20%23CCCCCC%3B%0Aborder%2Dradius%3A%205px%3B%0Abackground%2Dcolor%3A%20%23f6f6f6%3B%0Afont%2Dsize%3A%2013px%3B%0Aline%2Dheight%3A%201%2E3%3B%0A%7D%0A%23TOC%20%2Etoctitle%20%7B%0Afont%2Dweight%3A%20bold%3B%0Afont%2Dsize%3A%2015px%3B%0Amargin%2Dleft%3A%205px%3B%0A%7D%0A%23TOC%20ul%20%7B%0Apadding%2Dleft%3A%2040px%3B%0Amargin%2Dleft%3A%20%2D1%2E5em%3B%0Amargin%2Dtop%3A%205px%3B%0Amargin%2Dbottom%3A%205px%3B%0A%7D%0A%23TOC%20ul%20ul%20%7B%0Amargin%2Dleft%3A%20%2D2em%3B%0A%7D%0A%23TOC%20li%20%7B%0Aline%2Dheight%3A%2016px%3B%0A%7D%0Atable%20%7B%0Amargin%3A%201em%20auto%3B%0Aborder%2Dwidth%3A%201px%3B%0Aborder%2Dcolor%3A%20%23DDDDDD%3B%0Aborder%2Dstyle%3A%20outset%3B%0Aborder%2Dcollapse%3A%20collapse%3B%0A%7D%0Atable%20th%20%7B%0Aborder%2Dwidth%3A%202px%3B%0Apadding%3A%205px%3B%0Aborder%2Dstyle%3A%20inset%3B%0A%7D%0Atable%20td%20%7B%0Aborder%2Dwidth%3A%201px%3B%0Aborder%2Dstyle%3A%20inset%3B%0Aline%2Dheight%3A%2018px%3B%0Apadding%3A%205px%205px%3B%0A%7D%0Atable%2C%20table%20th%2C%20table%20td%20%7B%0Aborder%2Dleft%2Dstyle%3A%20none%3B%0Aborder%2Dright%2Dstyle%3A%20none%3B%0A%7D%0Atable%20thead%2C%20table%20tr%2Eeven%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0Ap%20%7B%0Amargin%3A%200%2E5em%200%3B%0A%7D%0Ablockquote%20%7B%0Abackground%2Dcolor%3A%20%23f6f6f6%3B%0Apadding%3A%200%2E25em%200%2E75em%3B%0A%7D%0Ahr%20%7B%0Aborder%2Dstyle%3A%20solid%3B%0Aborder%3A%20none%3B%0Aborder%2Dtop%3A%201px%20solid%20%23777%3B%0Amargin%3A%2028px%200%3B%0A%7D%0Adl%20%7B%0Amargin%2Dleft%3A%200%3B%0A%7D%0Adl%20dd%20%7B%0Amargin%2Dbottom%3A%2013px%3B%0Amargin%2Dleft%3A%2013px%3B%0A%7D%0Adl%20dt%20%7B%0Afont%2Dweight%3A%20bold%3B%0A%7D%0Aul%20%7B%0Amargin%2Dtop%3A%200%3B%0A%7D%0Aul%20li%20%7B%0Alist%2Dstyle%3A%20circle%20outside%3B%0A%7D%0Aul%20ul%20%7B%0Amargin%2Dbottom%3A%200%3B%0A%7D%0Apre%2C%20code%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0Aborder%2Dradius%3A%203px%3B%0Acolor%3A%20%23333%3B%0Awhite%2Dspace%3A%20pre%2Dwrap%3B%20%0A%7D%0Apre%20%7B%0Aborder%2Dradius%3A%203px%3B%0Amargin%3A%205px%200px%2010px%200px%3B%0Apadding%3A%2010px%3B%0A%7D%0Apre%3Anot%28%5Bclass%5D%29%20%7B%0Abackground%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0Acode%20%7B%0Afont%2Dfamily%3A%20Consolas%2C%20Monaco%2C%20%27Courier%20New%27%2C%20monospace%3B%0Afont%2Dsize%3A%2085%25%3B%0A%7D%0Ap%20%3E%20code%2C%20li%20%3E%20code%20%7B%0Apadding%3A%202px%200px%3B%0A%7D%0Adiv%2Efigure%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0Aimg%20%7B%0Abackground%2Dcolor%3A%20%23FFFFFF%3B%0Apadding%3A%202px%3B%0Aborder%3A%201px%20solid%20%23DDDDDD%3B%0Aborder%2Dradius%3A%203px%3B%0Aborder%3A%201px%20solid%20%23CCCCCC%3B%0Amargin%3A%200%205px%3B%0A%7D%0Ah1%20%7B%0Amargin%2Dtop%3A%200%3B%0Afont%2Dsize%3A%2035px%3B%0Aline%2Dheight%3A%2040px%3B%0A%7D%0Ah2%20%7B%0Aborder%2Dbottom%3A%204px%20solid%20%23f7f7f7%3B%0Apadding%2Dtop%3A%2010px%3B%0Apadding%2Dbottom%3A%202px%3B%0Afont%2Dsize%3A%20145%25%3B%0A%7D%0Ah3%20%7B%0Aborder%2Dbottom%3A%202px%20solid%20%23f7f7f7%3B%0Apadding%2Dtop%3A%2010px%3B%0Afont%2Dsize%3A%20120%25%3B%0A%7D%0Ah4%20%7B%0Aborder%2Dbottom%3A%201px%20solid%20%23f7f7f7%3B%0Amargin%2Dleft%3A%208px%3B%0Afont%2Dsize%3A%20105%25%3B%0A%7D%0Ah5%2C%20h6%20%7B%0Aborder%2Dbottom%3A%201px%20solid%20%23ccc%3B%0Afont%2Dsize%3A%20105%25%3B%0A%7D%0Aa%20%7B%0Acolor%3A%20%230033dd%3B%0Atext%2Ddecoration%3A%20none%3B%0A%7D%0Aa%3Ahover%20%7B%0Acolor%3A%20%236666ff%3B%20%7D%0Aa%3Avisited%20%7B%0Acolor%3A%20%23800080%3B%20%7D%0Aa%3Avisited%3Ahover%20%7B%0Acolor%3A%20%23BB00BB%3B%20%7D%0Aa%5Bhref%5E%3D%22http%3A%22%5D%20%7B%0Atext%2Ddecoration%3A%20underline%3B%20%7D%0Aa%5Bhref%5E%3D%22https%3A%22%5D%20%7B%0Atext%2Ddecoration%3A%20underline%3B%20%7D%0A%0Acode%20%3E%20span%2Ekw%20%7B%20color%3A%20%23555%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Edt%20%7B%20color%3A%20%23902000%3B%20%7D%20%0Acode%20%3E%20span%2Edv%20%7B%20color%3A%20%2340a070%3B%20%7D%20%0Acode%20%3E%20span%2Ebn%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Efl%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Ech%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Est%20%7B%20color%3A%20%23d14%3B%20%7D%20%0Acode%20%3E%20span%2Eco%20%7B%20color%3A%20%23888888%3B%20font%2Dstyle%3A%20italic%3B%20%7D%20%0Acode%20%3E%20span%2Eot%20%7B%20color%3A%20%23007020%3B%20%7D%20%0Acode%20%3E%20span%2Eal%20%7B%20color%3A%20%23ff0000%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%0Acode%20%3E%20span%2Efu%20%7B%20color%3A%20%23900%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%20code%20%3E%20span%2Eer%20%7B%20color%3A%20%23a61717%3B%20background%2Dcolor%3A%20%23e3d2d2%3B%20%7D%20%0A" rel="stylesheet" type="text/css" />

</head>

<body>




<h1 class="title toc-ignore">Get data from multiple netcdf files</h1>
<h4 class="author"><em>James McCreight</em></h4>
<h4 class="date"><em>2017-05-01</em></h4>



<div id="background" class="section level1">
<h1>Background</h1>
<p>The output of WRF Hydro model runs is spread over multiple netcdf files in time and over multiple netcdf files in different output categories (e.g CHRTOUT, LDASOUT). This tool presents a list-based approach to gathering all the timeseries data you need at once (over both time and output file types) with parallelization at the file level for enhanced speed. The main limitation is that each variable specified may only return a scalar for a given time. That is, if you want a timeseries of rasters you might approach this differently. However, arbitrary statistics can summarize spatial fields on user-defined masks. Or the same variable can be specified multiple times with different index to pull out a subset of the full domain (probably not efficient for large subsets).</p>
</div>
<div id="setup" class="section level1">
<h1>Setup</h1>
<p>Load the rwrfhydro package.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(<span class="st">&quot;rwrfhydro&quot;</span>)</code></pre></div>
<p>Set the WRF Hydro test case directory, this should be the only thing you need to customize to your machine. We’ll use daily data from the Fourmile Creek test case where the full routing physics are used.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">dataPath &lt;-<span class="st"> '~/wrfHydroTestCases/Fourmile_Creek_testcase_v2.0/run.FullRouting/'</span></code></pre></div>
</div>
<div id="list-based-data-retrieval" class="section level1">
<h1>List-based data retrieval</h1>
<p>The <code>GetMultiNcdf</code> function needs 3 <em>collated</em> lists as input: <code>filesList</code>, <code>variableList</code>, and <code>indexList</code> (e.g. <code>args(GetMultiNcdf)</code>). (Note these are the formal argument names which may be shortend when calling the function, by R rules, upto uniqueness of the argument name. We construct variables in the global workspace to pass to these functions which have similar but not identical names.)</p>
<div id="fileslist" class="section level2">
<h2><code>filesList</code></h2>
<p>This is a named list of arbitrary length. The individual entries correspond to different file types of model output and contain all the files you want to look at in the time series. These are usually generated by running <code>files.list()</code> in a directory. Here output files from the land surface model and RESTART files from the hydro model are desired. These are found individually and then placed into <code>fileList</code></p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">lsmFiles &lt;-<span class="st"> </span><span class="kw">list.files</span>(<span class="dt">path=</span>dataPath, <span class="dt">pattern=</span><span class="st">'LDASOUT_DOMAIN'</span>, <span class="dt">full.names=</span><span class="ot">TRUE</span>)
hydroFiles &lt;-<span class="st"> </span><span class="kw">list.files</span>(<span class="dt">path=</span>dataPath, <span class="dt">pattern=</span><span class="st">'HYDRO_RST'</span>, <span class="dt">full.names=</span><span class="ot">TRUE</span>)
flList &lt;-<span class="st"> </span><span class="kw">list</span>(<span class="dt">lsm=</span>lsmFiles, <span class="dt">hydro=</span>hydroFiles)</code></pre></div>
<p>Note that the output and restart frequencies are different from the number of files of each type.</p>
</div>
<div id="variablelist" class="section level2">
<h2><code>variableList</code></h2>
<p>All three lists are collated by the name assigned in the list. Now we define which variables are desired for each file group. From the land surface model (LSM) output files, we want the surface radiative temperature (TRAD) and the snow water equivalent (SNEQV). For the hydro restart files, we want streamflow and soil moisture on the four vertical soil layers. The layers are differentiated, for now, only by the names we give them (smc1-4). (HYDRO_RST files are somewhat unique in that they have variables with different dimensions, however they are typcially sparse in time, unless you are preforming data assimilation.)</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">lsmVars   &lt;-<span class="st"> </span><span class="kw">list</span>(<span class="dt">TRAD=</span><span class="st">'TRAD'</span>, <span class="dt">SWE=</span><span class="st">'SNEQV'</span>)
hydroVars &lt;-<span class="st"> </span><span class="kw">list</span>(<span class="dt">streamflow=</span><span class="st">'qlink1'</span>, <span class="dt">smc1=</span><span class="st">'sh2ox1'</span>, <span class="dt">smc2=</span><span class="st">'sh2ox2'</span>, <span class="dt">smc3=</span><span class="st">'sh2ox3'</span>, <span class="dt">smc4=</span><span class="st">'sh2ox4'</span>)
varList &lt;-<span class="st"> </span><span class="kw">list</span>(<span class="dt">lsm=</span>lsmVars, <span class="dt">hydro=</span>hydroVars)</code></pre></div>
</div>
<div id="indexlist" class="section level2">
<h2><code>indexList</code></h2>
<p>The <code>indexList</code> defines what indices/stats are desired for each variable in each file group. This list is collated with both of the previous two lists in a nested way, illustrated below.</p>
<p>Only a scalar can be returned for each entry specified index argument. However, spatial fields (over a range of indices) can be summarized using arbitrary statistics. We show how to define your own useful statistics which can be used when specifying the indexList. (Note that the envir argument may be needed to get your function inside of GetMultiNcdf in special circumstances.)</p>
<p>Our statistic example is to calculate basin-average radiative temperature, basin-maximum snow water equivalent, and basin-average soil moisture on each layer. Since all of these variables are on the low-res grid, we need the basin mask from the high-res grid resampled to the low-res geogrid. We use the CreateBasinMask function to generate a basin mask weight grid (each cell value is the fraction of basin within that cell). We specify the path to the high-res routing grid (which contains the basin mask variable), the basin ID we want to run (1), and the aggregation factor between the high-res and low-res grids (10).</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ncdf4)
basinMask &lt;-<span class="st"> </span><span class="kw">CreateBasinMask</span>(<span class="kw">paste0</span>(dataPath,<span class="st">'DOMAIN/Fulldom_hires_hydrofile.Fourmile100m.nc'</span>), 
                             <span class="dt">basid=</span><span class="dv">1</span>, <span class="dt">aggfact=</span><span class="dv">10</span>)</code></pre></div>
<p>Then, we use this resampled basin mask to setup basin mean and max functions, which determine the mean and maximum values of a variable within the basin mask.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">basAvg &lt;-<span class="st"> </span><span class="cf">function</span>(var) <span class="kw">sum</span>(basinMask<span class="op">*</span>var)<span class="op">/</span><span class="kw">sum</span>(basinMask)
basMax &lt;-<span class="st"> </span><span class="cf">function</span>(var) <span class="kw">max</span>(<span class="kw">ceiling</span>(basinMask)<span class="op">*</span>var)</code></pre></div>
<p>For fun, we can also calculate the size of the basin while we are here. The LSM pixels are 1km:</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">basinKm2 &lt;-<span class="st"> </span><span class="kw">sum</span>(basinMask)
basinKm2</code></pre></div>
<pre><code>## [1] 60.67</code></pre>
<p>Now we can construct the indexList. For the LSM, we want spatial summaries of TRAD and SNEQV at each time (note that SNEQV is a single layer). Statistical summaries are requested using a list for each variable. The list specifies a grid ‘slice’ or ‘hyperslab’ (as distinct from a subset, i.e. a slice is how ncdf4 lets one subset matrices) on which to compute a <em>named</em> statistic. The required names in this list are <code>start</code>, <code>end</code>, and <code>stat</code> in the list. We want the whole domain, and have to specify that. An <code>ncdump</code> of the first <code>lsmFile</code> shows the variable spatial dimensions, to help specify the start and end arguments.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ncdump</span>(lsmFiles[<span class="dv">1</span>])
<span class="co">#File: ~/Fourmile_Creek_testcase_v2.0/run.FullRouting//201210020000.LDASOUT_DOMAIN1</span>
<span class="co">#( NC_FORMAT_CLASSIC ):</span>
<span class="co">#dimensions (5):</span>
<span class="co">#    time = UNLIMITED ; // (1 currently)</span>
<span class="co">#    west_east = 21 ; </span>
<span class="co">#    south_north = 7 ; </span>
<span class="co">#    soil_layers_stag = 4 ; </span>
<span class="co">#    snow_layers = 3 ; </span>
<span class="co">#...</span></code></pre></div>
<p>So we construct</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">lsmInds   &lt;-<span class="st"> </span><span class="kw">list</span>(<span class="dt">TRAD=</span><span class="kw">list</span>(<span class="dt">start=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">1</span>), <span class="dt">end=</span><span class="kw">c</span>(<span class="dv">21</span>,<span class="dv">7</span>,<span class="dv">1</span>), <span class="dt">stat=</span><span class="st">'basAvg'</span>),
                  <span class="dt">SNEQV=</span><span class="kw">list</span>(<span class="dt">start=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">1</span>), <span class="dt">end=</span><span class="kw">c</span>(<span class="dv">21</span>,<span class="dv">7</span>,<span class="dv">1</span>), <span class="dt">stat=</span><span class="st">'basMax'</span>))</code></pre></div>
<p>and the mask is applied to the whole domain.</p>
<p>Similarly, we need the indices for the HYDRO_RST files. Here we want to get <em>layer-averaged</em> soil moisture so the lists are specified for the individual soil moisture layers, 1-4. <em>Note that the dimensions are reverse order from what is shown in “ncdump -h” on the command line and in rwrfhydro (thanks to ncdf4 package).</em> For the discharge, qlink1, also in the HYDRO_RST file we dont supply a list. Instead we only give the integer index where flow is desired. (See the “WRF Hydro Domain and Channel Visualization” vignette to understand why index 1 on the stream channel just happens, conincidentally, to be the basin outlet.)</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">hydroInds &lt;-<span class="st"> </span><span class="kw">list</span>(<span class="dt">qlink1=</span><span class="dv">1</span>,
                  <span class="dt">smc1=</span><span class="kw">list</span>(<span class="dt">start=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">1</span>), <span class="dt">end=</span><span class="kw">c</span>(<span class="dv">21</span>,<span class="dv">7</span>), <span class="dt">stat=</span><span class="st">'basAvg'</span>),
                  <span class="dt">smc2=</span><span class="kw">list</span>(<span class="dt">start=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">1</span>), <span class="dt">end=</span><span class="kw">c</span>(<span class="dv">21</span>,<span class="dv">7</span>), <span class="dt">stat=</span><span class="st">'basAvg'</span>),
                  <span class="dt">smc3=</span><span class="kw">list</span>(<span class="dt">start=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">1</span>), <span class="dt">end=</span><span class="kw">c</span>(<span class="dv">21</span>,<span class="dv">7</span>), <span class="dt">stat=</span><span class="st">'basAvg'</span>),
                  <span class="dt">smc4=</span><span class="kw">list</span>(<span class="dt">start=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">1</span>), <span class="dt">end=</span><span class="kw">c</span>(<span class="dv">21</span>,<span class="dv">7</span>), <span class="dt">stat=</span><span class="st">'basAvg'</span>) )
## Then we are ready to put them together
indList &lt;-<span class="st"> </span><span class="kw">list</span>(<span class="dt">lsm=</span>lsmInds, <span class="dt">hydro=</span>hydroInds)</code></pre></div>
</div>
<div id="getmultincdf" class="section level2">
<h2><code>GetMultiNcdf()</code></h2>
<p>All the work is really in setting up the lists. Now we just pass these to <code>GetMultiNcdf</code>. The preceeding two lines setup optional parallelization of the data grabs.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(doMC)   ## Showing parallelization for most unix, which is at the file level within each file 
<span class="kw">registerDoMC</span>(<span class="dv">3</span>) ##  groups, pointless to be longer than your timeseries. Set parallel=TRUE to use.
fileData &lt;-<span class="st"> </span><span class="kw">GetMultiNcdf</span>(<span class="dt">filesList=</span>flList, <span class="dt">variableList=</span>varList, <span class="dt">indexList=</span>indList, <span class="dt">parallel=</span><span class="ot">FALSE</span>)</code></pre></div>
<p>What did we get?</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">str</span>(fileData)</code></pre></div>
<pre><code>## 'data.frame':    663 obs. of  8 variables:
##  $ POSIXct      : POSIXct, format: &quot;2012-10-02&quot; &quot;2012-10-03&quot; &quot;2012-10-04&quot; &quot;2012-10-05&quot; ...
##  $ inds         : chr  &quot;1:21,1:7,1:1&quot; &quot;1:21,1:7,1:1&quot; &quot;1:21,1:7,1:1&quot; &quot;1:21,1:7,1:1&quot; ...
##  $ stat         : chr  &quot;basAvg&quot; &quot;basAvg&quot; &quot;basAvg&quot; &quot;basAvg&quot; ...
##  $ statArg      : chr  &quot;-&quot; &quot;-&quot; &quot;-&quot; &quot;-&quot; ...
##  $ variable     : Factor w/ 7 levels &quot;TRAD&quot;,&quot;SNEQV&quot;,..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ value        : num  285 286 289 278 277 ...
##  $ variableGroup: chr  &quot;TRAD&quot; &quot;TRAD&quot; &quot;TRAD&quot; &quot;TRAD&quot; ...
##  $ fileGroup    : chr  &quot;lsm&quot; &quot;lsm&quot; &quot;lsm&quot; &quot;lsm&quot; ...</code></pre>
<p>The <code>fileData</code> dataframe shows the time (<code>POSIXct</code>) at which certain indices (<code>inds</code>) were summarized with statistic <code>stat</code> for each <code>variable</code> (variable names in the file, e.g. sh2ox) The resulting <code>value</code> is given with the <code>variableGroup</code> (e.g. smc1-4 and not sh2ox) and <code>fileGroup</code>.</p>
</div>
</div>
<div id="plot-the-timeseries" class="section level1">
<h1>Plot the timeseries</h1>
<p>This output format is easily plotted using <code>ggplot2</code>.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(ggplot2)
<span class="kw">library</span>(scales)
<span class="kw">ggplot</span>(fileData, <span class="kw">aes</span>(<span class="dt">x=</span>POSIXct, <span class="dt">y=</span>value, <span class="dt">color=</span>fileGroup)) <span class="op">+</span>
<span class="st">  </span><span class="kw">geom_line</span>() <span class="op">+</span><span class="st"> </span><span class="kw">geom_point</span>() <span class="op">+</span>
<span class="st">  </span><span class="kw">facet_wrap</span>(<span class="op">~</span>variableGroup, <span class="dt">scales=</span><span class="st">'free_y'</span>, <span class="dt">ncol=</span><span class="dv">1</span>) <span class="op">+</span>
<span class="st">  </span><span class="kw">scale_x_datetime</span>(<span class="dt">breaks =</span> <span class="kw">date_breaks</span>(<span class="st">&quot;1 month&quot;</span>)) <span class="op">+</span><span class="st"> </span><span class="kw">theme_bw</span>()</code></pre></div>
<p><img src="" width="700" height="720" /></p>
</div>



<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>

</body>
</html>
